package com.bruce.utils.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

/**
 * @author luotuan
 * @Description
 * @create 2020-09-23 11:05
 **/
public class JsonCompareUtils {
    private static final String PROD_MEMBER_PATH = "$.requestObject.prodServTmpDetails.prodServTmpMembers";
    private void cpmpare(String newMsg,String oldMsg){

    }

    public static void main(String[] args) throws IOException {
        String filePath = "F:\\浩鲸云科技\\开发\\设计中心\\bo融合\\";
        String str1 = new String(Files.readAllBytes(Paths.get(filePath+"json1.txt")), StandardCharsets.UTF_8);
        String str2 = new String(Files.readAllBytes(Paths.get(filePath+"json2.txt")), StandardCharsets.UTF_8);
        JSONObject object = JSON.parseObject(str1);
        List<Long> result =  JSONObject.parseArray(JSONPath.extract(str1,PROD_MEMBER_PATH+".pstMemberId").toString(),Long.class);
        result.forEach(System.out::println);
        String ss = JSONPath.read(str1,PROD_MEMBER_PATH+"[?(@.pstMemberId=\"1\")][0]").toString();
        System.out.println(JSONPath.contains(str1,PROD_MEMBER_PATH+"[?(@.pstMemberId=\"1\")][0]"));
      //  System.out.println(JSONPath.read(str1,PROD_MEMBER_PATH+"[0]"));
        JSONPath.arrayAdd(object,"$.requestObject.prodServTmpDetails.prodServTmpMembers[0]",ss);

    }
}
